TPerlRe is just a class wrapper to interface with perlre.dll. I use Delphi4's overloading and default paramater quite a bit, so if you use an older version you'll have to make some modifications. The interface is as follows:
property RegExp: string
the regex pattern
property Options: integer
ORed values of the following: see pcre.html for explanation of these
options
PCRE_CASELESS
PCRE_MULTILINE
PCRE_DOTALL
PCRE_SINGLELINE
PCRE_EXTENDED
PCRE_ANCHORED
PCRE_DOLLAR_ENDONLY
PCRE_EXTRA
PCRE_NOTBOL
PCRE_NOTEOL
PCRE_UNGREEDY
property Text: string
subject text to match
property SubExp[I:integer]: TSubExp
returns info for the Ith subexpression, where 0th expression
is the entire matching string
TSubExp stores 1) the subexpression string; 2) the 1-based index
of the subexpression into Text; and 3) length of subexpression.
property SubExpCount: integer
returns how many sub expressions were matched (not incl. the 0th one)
First, I did not completely port some functions, notably those in maketables.c which allows you to define character tables for foreign languages and locales.
More importantly, I currently use a hack for freeing the (pcre *) and (pcre_extra *) pointers. Since I cannot use Delphi's dispose to free the memory allocated by the dll, I introduced a function called pcre_dispose in the dll and pass it the pointers to free (see next section). This seems to work fine but i realize it's not the customary or preferred way. If someone can improve this, please let me know.
I built the dll with MSVC++6. It's actually pretty simple. The first thing you need to do is compile the file deftables.c and run it. This will generate the file chartables.c, which you'll need to build the dll.
Next, create an empty win32 dll. Add the files pcre,c and study.c. If you want the posix-type interface, then add pcreposix.c. I didn't.
Next, you need to export some functions. Edit pcre.h and add __declspec(dllexport) to all the function declarations. For example: